package com.jdk.demo.thread.condition;

public class WorkThread extends Thread {

    TaskQueue taskQueue;

    public WorkThread(TaskQueue taskQueue) {
        this.taskQueue = taskQueue;
    }

    @Override
    public void run() {
        while (!isInterrupted()) {
            String name;
            try {
                name = taskQueue.getTask();
                System.out.println("Hello," + name + "!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }

    public static void main(String[] args) throws InterruptedException {
        TaskQueue taskQueue = new TaskQueue();
        WorkThread workThread = new WorkThread(taskQueue);
        workThread.start();
        for (int i = 1; i <= 3; i++) {
            taskQueue.addTask("线程" + i);
            Thread.sleep(1000);
        }
        System.out.println("END");

    }
    
}
